<template>
  <div class="mod-sp__spmatch">
    <el-form :inline="true" :model="dataForm" @keyup.enter="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.matchName" placeholder="赛事名称" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <ren-select v-model="dataForm.matchLevel" dict-type="matchLevel" placeholder="赛事等级"></ren-select>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">{{ $t("query") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="info" @click="exportHandle()">{{ $t("export") }}</el-button>
      </el-form-item>
      <!--
      <el-form-item>
        <el-button v-if="hasPermission('sp:spmatch:save')" type="primary" @click="addOrUpdateHandle()">{{ $t("add") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button v-if="hasPermission('sp:spmatch:delete')" type="danger" @click="deleteHandle()">{{ $t("deleteBatch") }}</el-button>
      </el-form-item>
      -->
    </el-form>
    <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" style="width: 100%">
      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
      <el-table-column width="200" prop="matchName" label="赛事名称" header-align="center" align="center">
        <template v-slot="scope">
          <el-button type="text" @click="showTypeList(scope.row)">{{ scope.row.matchName }}</el-button>
        </template>
      </el-table-column>
      <el-table-column width="120" prop="matchLevel" label="赛事等级" header-align="center" align="center">
        <template v-slot="scope">
          {{ getDictLabel("matchLevel", scope.row.matchLevel) }}
        </template>
      </el-table-column>
      <el-table-column width="200" prop="matchParentName" label="母赛事" header-align="center" align="center"></el-table-column>
      <el-table-column prop="province" label="省" header-align="center" align="center">
        <template v-slot="scope">
          {{ scope.row.province === "-1" ? "全国" : scope.row.province }}
        </template>
      </el-table-column>
      <el-table-column prop="city" label="市" header-align="center" align="center">
        <template v-slot="scope">
          {{ scope.row.city === "-1" ? "全部" : scope.row.city }}
        </template>
      </el-table-column>
      <el-table-column prop="isOpen" label="跨地区" header-align="center" align="center">
        <template v-slot="scope">
          {{ getDictLabel("isOpen", scope.row.isOpen) }}
        </template>
      </el-table-column>
      <el-table-column width="120" prop="season" label="赛季年度" header-align="center" align="center">
        <template v-slot="scope">
          {{ getDictLabel("season", scope.row.season) }}
        </template>
      </el-table-column>
      <el-table-column width="190" prop="beginDate" label="比赛时间起" header-align="center" align="center">
        <template v-slot="scope"> {{ scope.row.beginDate }} ~ {{ scope.row.endDate }} </template>
      </el-table-column>
      <el-table-column width="190" prop="beginSignup" label="报名时间起" header-align="center" align="center">
        <template v-slot="scope"> {{ scope.row.beginSignup }} ~ {{ scope.row.endSignup }} </template>
      </el-table-column>
      <el-table-column width="120" prop="adminId" label="管理员" header-align="center" align="center"></el-table-column>
      <el-table-column width="120" prop="status" label="赛事状态" header-align="center" align="center">
        <template v-slot="scope">
          {{ getDictLabel("matchStatus", scope.row.status) }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="200">
        <template v-slot="scope">
          <el-button v-if="hasPermission('sp:spmatch:update')" type="text" size="small" @click="toUserTicket(scope.row.id, '1')">领队证</el-button>
          <el-button v-if="hasPermission('sp:spmatch:delete')" type="text" size="small" @click="toUserTicket(scope.row.id, '2')">选手证件</el-button>
          <!--
          <el-button v-if="hasPermission('sp:spmatch:delete')" type="text" size="small" @click="toUserCertificate(scope.row.id)">获奖证书</el-button>
          -->
        </template>
      </el-table-column>
    </el-table>
    <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total" layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle" @current-change="pageCurrentChangeHandle"> </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    <!-- 字典类型数据 -->
    <el-drawer :title="focusDictTypeTitle" v-model="dictTypeListVisible" :size="800" close-on-press-escape="false" custom-class="rr-drawer"> <DictTypeList :dictTypeId="focusDictTypeId"></DictTypeList></el-drawer>
  </div>
</template>

<script lang="ts">
import useView from "@/hooks/useView";
import { defineComponent, reactive, toRefs } from "vue";
import AddOrUpdate from "./spmatch-add-or-update.vue";
import DictTypeList from "./spmatchitem4.vue";
import { IObject } from "@/types/interface";

export default defineComponent({
  components: {
    AddOrUpdate,
    DictTypeList
  },
  setup() {
    const state = reactive({
      getDataListURL: "/sp/spmatch/page",
      getDataListIsPage: true,
      exportURL: "/sp/spmatch/export",
      deleteURL: "/sp/spmatch",
      deleteIsBatch: true,
      dataForm: {
        matchName: "",
        matchLevel: ""
      },
      dictTypeListVisible: false,
      focusDictTypeId: "",
      focusDictTypeTitle: ""
    });
    return { ...useView(state), ...toRefs(state) };
  },
  watch: {},
  methods: {
    // 跳转参赛证
    toUserTicket(id?: string, type?: string) {
      this.$router.push({ path: "/sp/spuserticket", query: { id: id, type: type } });
    },
    // 跳转到荣誉证书
    toUserCertificate(id?: string) {
      // id：赛项id
      this.$router.push({ path: "/sp/spmatchcertificate", query: { id: id } });
    },
    showTypeList(row: IObject) {
      this.dictTypeListVisible = true;
      this.focusDictTypeId = row.id;
      this.focusDictTypeTitle = `${this.$route.meta.title} - ${row.matchName}`;
    }
  }
});
</script>
